PSPSDK=$(shell psp-config --pspsdk-path)
PSPDEV=$(shell psp-config --pspdev-path)
INCLUDE=$(PSPSDK)/include

all:    main

clean:
	rm -rf *~ *.o *.elf *.bin *.s *.bin *.BIN

CC       = psp-gcc
CFLAGS   := -D PSP -I $(INCLUDE) -W -Wall -O2 -G0 -fno-pic -mno-abicalls -w -fomit-frame-pointer

ASM      = psp-as

sdk.o: sdk.S
	$(ASM) sdk.S -o sdk.o


main.o: main.c
	$(CC) $(CFLAGS) -S main.c -o main.s
	$(ASM) main.s -o main.o

h2.o: h2.c
	$(CC) $(CFLAGS) -S h2.c -o h2.s
	$(ASM) h2.s -o h2.o

main: main.o h2.o sdk.o linker.x
	$(PSPDEV)/bin/psp-ld -T linker.x -L$(PSPSDK)/lib main.o sdk.o -o main.elf
	$(PSPDEV)/bin/psp-ld -T linker_loader.x -L$(PSPSDK)/lib h2.o sdk.o -o h2.elf
	$(PSPDEV)/bin/psp-strip -s h2.elf
	$(PSPDEV)/bin/psp-objcopy -O binary h2.elf H2.BIN
	$(PSPDEV)/bin/psp-strip -s main.elf
	$(PSPDEV)/bin/psp-objcopy -O binary main.elf H.BIN


